﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Erp.Migrations
{
    /// <inheritdoc />
    public partial class add_table_DrugCatalog : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "DrugBasInfoAssocChrgitmType",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DrugBasInfoId = table.Column<Guid>(type: "uuid", nullable: false),
                    ChrgitmTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugBasInfoAssocChrgitmType", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DrugCatalogGrant",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugCatalogGrant", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DrugCatalogType",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DrugTypeCodg = table.Column<string>(type: "text", nullable: false),
                    DrugTypeName = table.Column<string>(type: "text", nullable: false),
                    PubItemCatgeCodg = table.Column<string>(type: "text", nullable: false),
                    PubItemCatgeName = table.Column<string>(type: "text", nullable: false),
                    ValiFlag = table.Column<bool>(type: "boolean", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugCatalogType", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DrugCatalogType_DrugCatalogType_ParentId",
                        column: x => x.ParentId,
                        principalSchema: "Erp",
                        principalTable: "DrugCatalogType",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "DrugMedcWayGrp",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DrugMedcWayCatgeCode = table.Column<string>(type: "text", nullable: false),
                    DrugMedcWayCodg = table.Column<string>(type: "text", nullable: false),
                    DrugMedcWayName = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugMedcWayGrp", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DrugPrdr",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PrdrCodg = table.Column<string>(type: "text", nullable: false),
                    PrdrName = table.Column<string>(type: "text", nullable: false),
                    Pinyincode = table.Column<string>(type: "text", nullable: true),
                    Wubicode = table.Column<string>(type: "text", nullable: true),
                    Coner = table.Column<string>(type: "text", nullable: true),
                    Tel = table.Column<string>(type: "text", nullable: true),
                    ChkerCodg = table.Column<string>(type: "text", nullable: true),
                    ChkerName = table.Column<string>(type: "text", nullable: true),
                    ChkTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    ValiFlag = table.Column<bool>(type: "boolean", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugPrdr", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DrugCatalog",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DrugCatalogTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    DrugCatalogTypeName = table.Column<string>(type: "text", nullable: false),
                    PhamTypeCodg = table.Column<string>(type: "text", nullable: false),
                    PhamTypeName = table.Column<string>(type: "text", nullable: false),
                    DrugCode = table.Column<string>(type: "text", nullable: false),
                    DrugName = table.Column<string>(type: "text", nullable: false),
                    DrugGenname = table.Column<string>(type: "text", nullable: false),
                    Alis = table.Column<string>(type: "text", nullable: true),
                    Pinyincode = table.Column<string>(type: "text", nullable: true),
                    Wubicode = table.Column<string>(type: "text", nullable: true),
                    DrugDosformCodg = table.Column<string>(type: "text", nullable: false),
                    DrugDosformName = table.Column<string>(type: "text", nullable: false),
                    DrugMedcWayCodg = table.Column<string>(type: "text", nullable: false),
                    DrugMedcWayName = table.Column<string>(type: "text", nullable: false),
                    DrugUsedFrquCodg = table.Column<string>(type: "text", nullable: false),
                    DrugUsedFrquName = table.Column<string>(type: "text", nullable: false),
                    ValuableFlag = table.Column<bool>(type: "boolean", nullable: false),
                    PoisonFlag = table.Column<bool>(type: "boolean", nullable: false),
                    EphedrineFlag = table.Column<bool>(type: "boolean", nullable: false),
                    PsychotropicDrugs1Flag = table.Column<bool>(type: "boolean", nullable: false),
                    PsychotropicDrugs2Flag = table.Column<bool>(type: "boolean", nullable: false),
                    RadiopharmaceuticalsFlag = table.Column<bool>(type: "boolean", nullable: false),
                    NewDrugFlag = table.Column<bool>(type: "boolean", nullable: false),
                    AuditFlag = table.Column<bool>(type: "boolean", nullable: false),
                    PublicityFlag = table.Column<bool>(type: "boolean", nullable: false),
                    ChineseHerbFlag = table.Column<bool>(type: "boolean", nullable: false),
                    NonDecoctionFlag = table.Column<bool>(type: "boolean", nullable: false),
                    PharmacyUseFlag = table.Column<bool>(type: "boolean", nullable: false),
                    LargeInfusionDrugsFlag = table.Column<bool>(type: "boolean", nullable: false),
                    BasicMedicationFlag = table.Column<bool>(type: "boolean", nullable: false),
                    MedicareMedicationFlag = table.Column<bool>(type: "boolean", nullable: false),
                    HomemadeDrugsFlag = table.Column<bool>(type: "boolean", nullable: false),
                    SkinTestDrugFlag = table.Column<bool>(type: "boolean", nullable: false),
                    OutpatientControlFlag = table.Column<bool>(type: "boolean", nullable: false),
                    PrescriptionDrugFlag = table.Column<bool>(type: "boolean", nullable: true),
                    ValiFlag = table.Column<bool>(type: "boolean", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugCatalog", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DrugCatalog_DrugCatalogType_DrugCatalogTypeId",
                        column: x => x.DrugCatalogTypeId,
                        principalSchema: "Erp",
                        principalTable: "DrugCatalogType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "DrugCatalogExt",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DrugCatalogId = table.Column<Guid>(type: "uuid", nullable: false),
                    DrugCodg = table.Column<string>(type: "text", nullable: false),
                    Pinyincode = table.Column<string>(type: "text", nullable: true),
                    Wubicode = table.Column<string>(type: "text", nullable: true),
                    DrugSpec = table.Column<string>(type: "text", nullable: false),
                    EachDos = table.Column<decimal>(type: "numeric", nullable: false),
                    MinUntCode = table.Column<string>(type: "text", nullable: false),
                    MinUntName = table.Column<string>(type: "text", nullable: false),
                    MinUseuntCode = table.Column<string>(type: "text", nullable: false),
                    MinUseuntName = table.Column<string>(type: "text", nullable: false),
                    MinSaluntCode = table.Column<string>(type: "text", nullable: false),
                    MinSaluntName = table.Column<string>(type: "text", nullable: false),
                    MinPacCnt = table.Column<decimal>(type: "numeric", nullable: false),
                    MinPacuntCode = table.Column<string>(type: "text", nullable: false),
                    MinPacuntName = table.Column<string>(type: "text", nullable: false),
                    MinPrepuntCode = table.Column<string>(type: "text", nullable: false),
                    MinPrepuntName = table.Column<string>(type: "text", nullable: false),
                    StoinPric = table.Column<decimal>(type: "numeric", nullable: true),
                    RtalPric = table.Column<decimal>(type: "numeric", nullable: true),
                    PrcuntTypeCode = table.Column<string>(type: "text", nullable: false),
                    PrcuntTypeName = table.Column<string>(type: "text", nullable: false),
                    DrugTracCodg = table.Column<string>(type: "text", nullable: true),
                    DrugProdBarc = table.Column<string>(type: "text", nullable: true),
                    Ddd = table.Column<string>(type: "text", nullable: true),
                    DrugPrdrId = table.Column<Guid>(type: "uuid", nullable: false),
                    Aprvno = table.Column<string>(type: "text", nullable: true),
                    Manl = table.Column<string>(type: "text", nullable: true),
                    ValiFlag = table.Column<bool>(type: "boolean", nullable: false),
                    ChkFlag = table.Column<bool>(type: "boolean", nullable: false),
                    ChkerId = table.Column<Guid>(type: "uuid", nullable: true),
                    ChkerName = table.Column<string>(type: "text", nullable: true),
                    ChkTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugCatalogExt", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DrugCatalogExt_DrugCatalog_DrugCatalogId",
                        column: x => x.DrugCatalogId,
                        principalSchema: "Erp",
                        principalTable: "DrugCatalog",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_DrugCatalogExt_DrugPrdr_DrugPrdrId",
                        column: x => x.DrugPrdrId,
                        principalSchema: "Erp",
                        principalTable: "DrugPrdr",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_DrugCatalog_DrugCatalogTypeId",
                schema: "Erp",
                table: "DrugCatalog",
                column: "DrugCatalogTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_DrugCatalogExt_DrugCatalogId",
                schema: "Erp",
                table: "DrugCatalogExt",
                column: "DrugCatalogId");

            migrationBuilder.CreateIndex(
                name: "IX_DrugCatalogExt_DrugPrdrId",
                schema: "Erp",
                table: "DrugCatalogExt",
                column: "DrugPrdrId");

            migrationBuilder.CreateIndex(
                name: "IX_DrugCatalogType_ParentId",
                schema: "Erp",
                table: "DrugCatalogType",
                column: "ParentId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "DrugBasInfoAssocChrgitmType",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "DrugCatalogExt",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "DrugCatalogGrant",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "DrugMedcWayGrp",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "DrugCatalog",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "DrugPrdr",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "DrugCatalogType",
                schema: "Erp");
        }
    }
}
